<cfsilent>
<!---
Kalendar Admin

COPYRIGHT & LICENSING INFO
-------------------------------------------------------------------

Copyright 2006 TJ Downes - tdownes@sanative.net - http://www.sanative.net

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

--->

	<cfparam name="url.AppAction" default="preferences"/>
	<cfparam name="URL.fromPublic" default="false"/>
	<!--- Add  defaults to this default struct. Values will override user input, URL and FORM scopes --->
	<cfset defaultStruct = structNew() >
	<cfset defaultStruct.isAdminMode = true />

	<!--- Load Model --->
	<cfset KalendarRequest = LightWire.getTransient("KalendarRequest").init( argumentcollection=KalendarService.loadInput( URL, Form, defaultStruct ) ) />
	<cfset KalendarEvent = LightWire.getTransient("KalendarEvent").init( argumentcollection=KalendarService.loadInput( URL, Form, defaultStruct ) ) />
	<cfset UserMsg = LightWire.getTransient("UserMsg") />
	
	<cfif KalendarConfig.getUseFCKEditor() is true>
		<cfset FCKEditor = LightWire.getTransient("FCKEditor") />
	</cfif>

</cfsilent>
<cfcontent reset="true"/>
<cfinclude template="header.cfm">

<cfswitch expression="#KalendarRequest.getAppAction()#">
	
	<cfcase value="ProcessEventForm,ShowEventForm,addRecord,editRecord,deleteRecord" delimiters=",">
		<cfif KalendarRequest.getAppAction() IS "editRecord">
			<cfset KalendarEvent = KalendarService.loadEvent( KalendarEvent )/> 
			<cfset KalendarEvent.setAppAction("editRecord")/>
		</cfif>
        <cfinclude template="display_form.cfm" />
  </cfcase>
	
	<cfcase value="addCategory,editCategory,deleteCategory" delimiters=",">
		<cfinclude template="categories.cfm" />
	</cfcase>
	
	<cfcase value="preferences" delimiters=",">
		<cfinclude template="display_preferences.cfm" />
	</cfcase>
<!--- 	
	<cfcase value="addCategory,editCategory,createCategory,updateCategory">
		<cfinclude template="categories.cfm" />
	</cfcase>		
 --->
	<cfcase value="displayImportForms,displayImportData" delimiters=",">
		<cfinclude template="importer.cfm" />
	</cfcase>
	
	<cfcase value="importData">
		<cfloop index="x" from="1" to="#arraylen(session.results)#">
			<cfif StructKeyExists(form, x)>
				<cfset session.results[x].CategoryID = KalendarConfig.getDefaultCategoryID()/>
				<cfset session.results[x].userID = session.user.getUserID()/>
				<cfset session.results[x].role = session.user.getRole()/>
				<cfset KalendarService.loadCommand("addRecord").execute(KalendarEvent.init(argumentCollection = session.results[x]),UserMsg.init())>
			</cfif>
		</cfloop>
		<cfset StructDelete(session, "results") />
		Import Complete. It is recommended that you review your imported items to verify that they match the format you expect.
	</cfcase>
</cfswitch>

<cfinclude template="footer.cfm">